import { BaseObjDetailData } from "../common/BaseObjDetailData";
import { NodeTypeHelper } from "./NodeTypeHelper";
import { BaseCmpData } from "../common/BaseCmpData";
import { EObjCmpType } from "../common/EObjCmpType";
import { Data_Transform3D } from "../common/Data_Transform3D";
import { Data_Vec3 } from "../common/Data_Vec3";
import MathEx from "../../../LTGame/Utils/MathEx";
import { Data_Scene3D } from "../common/Data_Scene3D";
import { Data_Camera } from "../common/Data_Camera";
import { Data_Vec4 } from "../common/Data_Vec4";

export class NodeDetailHelper {

    static WrapBaseDetail(node: Laya.Node): BaseCmpData {
        let cmp = new BaseCmpData();
        cmp.type = EObjCmpType.Base;
        let data = new BaseObjDetailData();
        data.name = node.name;
        data.type = NodeTypeHelper.GetNodeType(node);
        data.active = this.GetNodeActive(node);
        cmp.data = data;
        return cmp;
    }

    static WrapTransform3D(trans: Laya.Transform3D): BaseCmpData {
        let cmp = new BaseCmpData();
        cmp.type = EObjCmpType.Transform3D;
        let data = new Data_Transform3D();
        data.pos = new Data_Vec3();
        data.pos.x = MathEx.WrapFloat(trans.localPositionX);
        data.pos.y = MathEx.WrapFloat(trans.localPositionY);
        data.pos.z = MathEx.WrapFloat(trans.localPositionZ);

        data.rot = new Data_Vec3();
        data.rot.x = MathEx.WrapFloat(trans.localRotationEulerX);
        data.rot.y = MathEx.WrapFloat(trans.localRotationEulerY);
        data.rot.z = MathEx.WrapFloat(trans.localRotationEulerZ);

        data.scale = new Data_Vec3();
        data.scale.x = MathEx.WrapFloat(trans.localScaleX);
        data.scale.y = MathEx.WrapFloat(trans.localScaleY);
        data.scale.z = MathEx.WrapFloat(trans.localScaleZ);

        cmp.data = data;
        return cmp;
    }

    static WrapScene3D(scene3d: Laya.Scene3D): BaseCmpData {
        let cmp = new BaseCmpData();
        cmp.type = EObjCmpType.Scene3D;

        let data = new Data_Scene3D();
        data.enableFog = scene3d.enableFog;
        data.fogColor = new Data_Vec3(scene3d.fogColor);
        data.fogStart = scene3d.fogStart;
        data.fogRange = scene3d.fogRange;

        data.ambientMode = scene3d.ambientMode;
        data.ambientColor = new Data_Vec3(scene3d.ambientColor);
        data.ambientSphericalHarmonicsIntensity = scene3d.ambientSphericalHarmonicsIntensity;

        cmp.data = data;

        return cmp;
    }

    static WrapCamera(camera: Laya.Camera): BaseCmpData {
        let cmp = new BaseCmpData();

        cmp.type = EObjCmpType.Camera;

        let data = new Data_Camera();
        data.enableRender = camera.enableRender;
        data.enableHDR = camera.enableHDR;
        data.clearFlag = camera.clearFlag;
        data.aspectRatio = camera.aspectRatio;
        data.depthTextureMode = camera.depthTextureMode;
        data.nearPlane = camera.nearPlane;
        data.farPlane = camera.farPlane;
        data.clearColor = new Data_Vec4(camera.clearColor);
        data.cullingMask = camera.cullingMask;
        data.useOcclusionCulling = camera.useOcclusionCulling;
        data.fieldOfView = camera.fieldOfView;
        data.orthographic = camera.orthographic;
        data.orthographicVerticalSize = camera.orthographicVerticalSize;
        data.renderingOrder = camera.renderingOrder;

        cmp.data = data;

        return cmp;
    }

    static GetNodeActive(node: Laya.Node): boolean {
        if (node instanceof Laya.Stage) {
            return node.visible;
        } else if (node instanceof Laya.Sprite) {
            return node.visible;
        } else if (node instanceof Laya.Sprite3D) {
            return node.active;
        } else {
            console.error("未处理的node类型", node);
            return false;
        }
    }

    static SetNodeActive(node: Laya.Node, active: boolean) {
        if (node instanceof Laya.Stage) {
            node.visible = active;
        } else if (node instanceof Laya.Sprite) {
            node.visible = active;
        } else if (node instanceof Laya.Sprite3D) {
            node.active = active;
        } else {
            console.error("未处理的node类型", node);
        }
    }

}